<template>
  <div class="xtx-infinite-loading" ref="container">
    <div class="loading" v-if="loading">
      <span class="img"></span>
      <span class="text">正在加载...</span>
    </div>
    <div class="none" v-if="finished">
      <span class="img"></span>
      <span class="text">亲，没有更多了</span>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    loading: {
      type: Boolean,
      default: false
    },
    finished: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      container: null
    }
  },
  mounted() {
    var obj = this.$refs.container
    // console.log(obj);
    const observer = new IntersectionObserver(([{ isIntersecting }]) => {
    if (isIntersecting) {
      // 到达可视区停止观察
      // observer.unobserve(obj);
      // 函数调用
    //  console.log('到达可视区');
      // if(this.loading&&this.finished==false){
      //   this.$emit('getTop')
      // }
      if(!this.loading&&!this.finished){
        // console.log(213);
        this.$emit('getdata')
      }
    }
  }, {});
  observer.observe(obj);
  },
}
</script>

<style scoped lang='scss'>
.xtx-infinite-loading {
  .loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 200px;
    .img {
      width: 50px;
      height: 50px;
      background: url(@/assets/加载.gif) no-repeat center / contain;
    }
    .text {
      color: #999;
      font-size: 16px;
    }
  }
  .none {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 200px;
    .img {
      width: 200px;
      height: 134px;
      background: url(@/assets/空.png) no-repeat center / contain;
    }
    .text {
      color: #999;
      font-size: 16px;
    }
  }
}
</style>